package Test3;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 有以下double数组：
 * 		double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
 * 	请编程计算它们的总值及平均值(四舍五入保留小数点后2位)
 */
public class Test5 {
    public static void main(String[] args) {
        double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
        double sum=0;
        for (int i = 0; i < arr.length; i++) {
            double s=arr[i];

            sum+=s;
        }
        BigDecimal bigDecimal=new BigDecimal(sum);
        BigDecimal bigDecimal1=new BigDecimal(arr.length);
        BigDecimal divide= bigDecimal.divide(bigDecimal1, 2, BigDecimal.ROUND_HALF_UP);
        System.out.println(sum);
        System.out.println(divide);
    }
}
